package ObjectVC;

import java.util.ArrayList;
import java.util.Date;

public aspect Rollback {
	after(Object actualObj, Action action, ArrayList<Object> actionParams): 
		VCOperations.VCops(actualObj, action, actionParams) 
		&& if(action.equals(Action.Rollback)){
		if (null != actionParams && actionParams.size()>0){
			Object obj = actionParams.get(0);
			Integer idx = null;
			Date timestamp = null;
			
			if(actionParams.size()==1)
				actualObj = DB.getLatestVersion(obj);
			
			else if(actionParams.size()==2){
				if(actionParams.get(1).getClass().equals(Integer.class)) {
					idx = (Integer) actionParams.get(1);
					actualObj = DB.getVersion(obj, idx);
				}
				else if(actionParams.get(1).getClass().equals(Date.class)) {
					timestamp = (Date) actionParams.get(1);
					actualObj = DB.getVersion(obj, timestamp);
				}
			}
		}
	}
}
